package com.bootdo.system.vo;

import com.bootdo.common.exception.ExceptionEnum;
import lombok.Data;

/**
 * @description 自定义返回值
 * @Author YF
 * @Date 日期:2021/4/12 时间:20:16
 */
@Data
public class ResultInfo<T> {
    private    T    entiry;
    private Integer code;
    private String message;

    public ResultInfo() {
        this.code = 0;
        this.message = "操作成功";
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public ResultInfo(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ResultInfo ok(){
        return new ResultInfo(0, "操作成功");
    }

    public static ResultInfo ok(String msg){
        return new ResultInfo(0, msg);
    }

    public static ResultInfo error(){
        return new ResultInfo(500, "操作失败");
    }

    public static ResultInfo error(String msg){
        return new ResultInfo(500, msg);
    }

    public static ResultInfo error(Integer code, String msg){
        return new ResultInfo(code, msg);
    }

    public static ResultInfo error(ExceptionEnum exceptionEnum){
        return new ResultInfo(exceptionEnum.getStatus(), exceptionEnum.getMessage());
    }

    public ResultInfo(T entiry) {
        this.code = 0;
        this.message = "操作成功";
        this.entiry = entiry;
    }


}
